<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>全局组建和局部组件</title>
</head>
<body>
<div id="app">
  <cpn></cpn>
  <partcpn></partcpn>
</div>
<hr>
<div id="app2">
  <cpn></cpn>
</div>

<script src="../js/vue.js"></script>
<script>
  // 1、创建组件构造器
  const cpnC = Vue.extend({
    template: `
      <div>
        <h2>这是标题</h2>
        <p>这是内容，哈哈哈哈</p>
      </div>`
  })

  const cpnC2 = Vue.extend({
    template: `
      <div><p>这是局部组件的内容，哈哈哈哈</p></div>`
  })

  // 2、注册组件(这里注册的组件都是--全局组件)
  Vue.component('cpn', cpnC);

  /*在注册局部组件实例以外的地方用局部组件的标签，内容会不显示
  并且控制台打印异常信息： Unknown custom element: <partcpn> - did you register the component
                        correctly? For recursive components, make sure to provide the "name" option.*/
  const app = new Vue({
    el: '#app',
    data: {},
    components: { // 注册(局部组件)，只在app实例生效,格式--- key:组件标签的名称  value：组建构造器对象
      partcpn: cpnC2
    }
  });

  const app2 = new Vue({
    el: '#app2'
  });



</script>
</body>
</html>
